package com.java.service;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.java.entity.Supplier;
import com.java.entity.SupplierQuotation;

/**
 * 供应商产品报价管理服务
 * @author wqf
 * @version  Nov 24, 2011 11:51:06 AM
 */
@Transactional(propagation = Propagation.REQUIRED,readOnly=false, rollbackFor = Exception.class)
public class SupplierQuotationService extends BaseService{

	/**
	 * 添加
	 * @param SupplierQuotation
	 */
	public void addSupplierQuotation(SupplierQuotation obj){
		this.dao.saveObject(obj);
	}
	
	/**
	 * 编辑（for dwr）
	 * @param SupplierQuotation
	 */
	public void editSupplierQuotation(SupplierQuotation obj){
		if(null == obj.getId()){
			this.addSupplierQuotation(obj);
		}else{
			this.updateSupplierQuotation(obj);
		}
	}	
	
	/**
	 * 修改
	 * @param SupplierQuotation
	 */
	public void updateSupplierQuotation(SupplierQuotation obj){
		this.dao.updateObject(obj);
	}
	
	/**
	 * 删除
	 * @param id
	 */
	public void deleteSupplierQuotation(Long id){
		SupplierQuotation obj = this.dao.loadObject(SupplierQuotation.class, id);
		this.dao.deleteObject(obj);
	}
	
	public void deleteSupplierQuotationByIds(String ids){
		if(StringUtils.isNotBlank(ids)){
			String []id  = ids.split(",");
			for(String s:id){
				deleteSupplierQuotation(Long.parseLong(s));
			}			
		}	
	}

	public SupplierQuotation getSupplierQuotationById(Long id){
		return this.dao.loadObject(SupplierQuotation.class, id);
	}
		
	public List<SupplierQuotation> getSupplierQuotationByIds(String ids){
		if(StringUtils.isNotBlank(ids)){
			return this.dao.loadObjects(SupplierQuotation.class, "id in(" + ids + ")", "id desc", null, null);			
		}
		return null;
	}
}
